#include "mpLog.h"
#include "mpLocaleUtils.h"
#include "mpDateUtils.h"
#include "mpDateUtilsTests.h"

#include <chrono>

mpDateUtilsTests::mpDateUtilsTests()
{
}

void mpDateUtilsTests::initTestCase(){}
void mpDateUtilsTests::cleanupTestCase(){}



void mpDateUtilsTests::case_getSystemTime(){
#ifdef TEST_STRATEGY_COMPLETED

    //获取当前time_t
    time_t now_time= MP::DateUtils::get_now_time();
    //time_t自定义格式化化输出
    std::string time_to_local_date_string = MP::DateUtils::time_to_local_date_string(now_time);
    std::string time_to_local_datetime_string = MP::DateUtils::time_to_local_datetime_string(now_time);
    std::string time_to_cusom_datetime_string = MP::DateUtils::time_to_local_datetime_string(now_time,"%Y年%m月%d日 %H时%M分%S秒");

    MPLOG_INFO << "[time_to_local_date_string]:" << time_to_local_date_string;
    MPLOG_INFO << "[time_to_local_datetime_string]:" << time_to_local_datetime_string;
    MPLOG_INFO << "[time_to_cusom_datetime_string]:" << SYS_TEXT(time_to_cusom_datetime_string);


    //获取各类当前时间
    std::string now_local_date_string = MP::DateUtils::get_now_local_date_string();
    std::string now_local_datetime_string = MP::DateUtils::get_now_local_datetime_string();
    std::string now_local_datetime_string_withms = MP::DateUtils::get_now_local_datetime_string_withms();
    std::string now_gmt_string_iso8601 = MP::DateUtils::get_now_gmt_string_iso8601();
    std::string now_gmt_string = MP::DateUtils::get_now_gmt_string();

    MPLOG_INFO << "[now_local_date_string]:" << now_local_date_string;
    MPLOG_INFO << "[now_local_datetime_string]:" << now_local_datetime_string;
    MPLOG_INFO << "[now_local_datetime_string_withms]:" << now_local_datetime_string_withms;
    MPLOG_INFO << "[now_gmt_string_iso8601]:" << now_gmt_string_iso8601;
    MPLOG_INFO << "[now_gmt_string]:" << now_gmt_string;

    //字符串转time_t
    time_t tmp;
    MP::DateUtils::string_to_time(time_to_local_datetime_string,"%d-%d-%d %d:%d:%d",tmp);
    std::string time_to_cusom_datetime_string2 = MP::DateUtils::time_to_local_datetime_string(now_time,"%Y年%m月%d日");
    MPLOG_INFO << "[string_to_time]:" << SYS_TEXT(time_to_cusom_datetime_string2);

    MPLOG_INFO << "[getsec_now_from_2000]: " << MP::DateUtils::getsec_now_from_2000() << endl;

    time_t custom_time;
    MP::DateUtils::custom_time(custom_time,2000,1,2);
    MPLOG_INFO << "[custom_time]:" << MP::DateUtils::time_to_local_datetime_string(custom_time);
    MPLOG_INFO << "[custom_time from 2000 sec count]: " << MP::DateUtils::getsec_time_from_2000(custom_time);

    MP::DateUtils::time_add_days(custom_time,1);
    MPLOG_INFO << "[custom_time add one day]:" << MP::DateUtils::time_to_local_datetime_string(custom_time);

    bool is_now_before_time = MP::DateUtils::is_now_before_time(2100,1,1);
    QVERIFY2(is_now_before_time,"is_now_before_time(2100,1,1)");
    is_now_before_time = MP::DateUtils::is_now_before_time(2000,1,1);
    QVERIFY2(!is_now_before_time,"is_now_before_time(2000,1,1)");


#endif

}

//void string_to_time_test(const std::string& str,
//                         const std::string& format){

//    std::cout << "transform [" << Utf8ToGbk(str.c_str()) << "] to time_t , format [" << Utf8ToGbk(format.c_str()) << "]" << std::endl;

//    time_t time;
//    if(MP::DateUtils::string_to_time(str,format,time)){
//        std::cout << "transform success,result = " <<  MP::DateUtils::time_to_local_datetime_string(time).c_str() << std::endl;
//    }
//    else{
//        std::cout << "transform faile" << std::endl;
//    }

//    std::cout << std::endl;
//}


//int main()
//{
//    cout << "get_now_local_date_string : " << MP::DateUtils::get_now_local_date_string() << endl;
//    cout << "get_now_local_datetime_string: " << MP::DateUtils::get_now_local_datetime_string() << endl;
//    cout << "get_now_local_datetime_string_withms: " << MP::DateUtils::get_now_local_datetime_string_withms() << endl;
//    cout << "get_now_local_datetime_string(cummon): " << MP::DateUtils::get_now_local_datetime_string("%Y/%m/%d") << endl;
//    cout << "get_now_gmt_string: " << MP::DateUtils::get_now_gmt_string() << endl;
//    cout << "get_now_gmt_string_iso8601: " << MP::DateUtils::get_now_gmt_string_iso8601() << endl;

//    time_t custom_time;
//    MP::DateUtils::custom_time(custom_time,2000,1,2);
//    cout << "getsec_now_from_2000: " << MP::DateUtils::getsec_now_from_2000() << endl;
//    cout << "getsec_now_from_2000: " << MP::DateUtils::getsec_time_from_2000(custom_time) << endl;
//    cout << "is_now_before_time: " << MP::DateUtils::is_now_before_time(custom_time) << endl;


//    string_to_time_test("2021-10-12 15:23:31","%d-%d-%d %d:%d:%d");
//    string_to_time_test("2021年10月12日","%d年%d月%d日");
//    return 0;
//}
